package com.cy.jt.controller;

import com.cy.jt.pojo.Item;
import com.cy.jt.service.ItemService;
import com.cy.jt.vo.ItemVO;
import com.cy.jt.vo.PageResult;
import com.cy.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/8/8 11:00
 */
@RestController
@RequestMapping("/item")
@CrossOrigin
public class ItemController {

    @Autowired
    private ItemService itemService;

//    get("/item/getItemList", {params: this.queryItemInfo})
    @GetMapping("/getItemList")
    public SysResult getItemList(PageResult pageResult){
        pageResult = itemService.getItemList(pageResult);
        return SysResult.success(pageResult);
    }

//    put("/item/updateItemStatus", {id: item.id,status: item.status})
    @PutMapping("/updateItemStatus")
    public SysResult updateItemStatus(@RequestBody Item item){
        itemService.updateItemStatus(item);
        return SysResult.success();
    }

//    delete("/item/deleteItemById", {params: {id: item.id}})
    @DeleteMapping("/deleteItemById/{id}")
    public SysResult deleteItemById(@PathVariable Integer id){
        System.out.println(id);
        itemService.deleteItemById(id);
        return SysResult.success();
    }

//    post("/item/saveItem",{ item : this.addItemForm, itemDesc: this.itemDesc })
    @PostMapping("/saveItem")
    public SysResult saveItem(@RequestBody ItemVO itemVO){ // 接收JSON
        itemService.saveItem(itemVO);
        return SysResult.success();
    }
}
